import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Schnell here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Schnell extends Gegner
{
    int v; // Momentangeschwindigkeit
    int a; // Beschleunigung
    int s = 8; // Sprungbewegung
    int h = -1;
    boolean sprung = false;

    public Schnell(int l)
    {
        super(l);
        super.hp = l*20;
        super.speed = 8;
        a = 1;
        v = -1;
    }

    /**
     * Act - do whatever the Gegner wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        super.act();
        if(getX() > 1024 || getX() < 0) return;
        //if(Greenfoot.getRandomNumber(10)<3) v = -v;
        if(Greenfoot.getRandomNumber(10)<1) a = -a;
        if(Greenfoot.getRandomNumber(100)<3 || sprung == true) springen();
        if(v >= speed || v <= -speed) v = 0;
        if(v == 0)
        {
            schießen();
            if(Greenfoot.getRandomNumber(2) == 0) v = 1;
            else v = -1;
        }
        else
        {  
            v = v + a;
            bewegen();
        }
    }    

    public void schießen()
    {
        if(Greenfoot.getRandomNumber(100)<2) super.schießen(true, 8, 10, "steel-ball.png");
    }

    public void bewegen()
    {
        setLocation(getX() + v, getY());
        if(getX() < 10) 
        {
            v = 1;
        }
        else if(getX() > 990)
        {
            v = -1;
        }
    }

    public void springen()
    {
        if(s < -8)
        {
            sprung = false;
            h = -h;
            s = 8;
        }
        else if(s == 0)
        {
            h = -h;
            s--;
        }
        else
        {
            sprung = true;
            setLocation(getX(), getY() + h*s*s);
            s--;
        }
    }

}
